<template>
  <div class="tabbar-user">
    <user-header :userInfo="userInfo" />
    <user-my-team v-if="!isNormalUser" :teamData="teamData" />
    <user-focus :baseData="baseData" />
    <user-invite :normalUser="isNormalUser" :partnerType="partnerType" />
    <order-group />
    <user-module />
    <!-- <coupon-group />
        <user-module />-->
  </div>
</template>

<script>
import userHeader from './user-header';
import orderGroup from './tabbar-user-order';
import userModule from './tabbar-user-module';
import userMyTeam from './user-myteam.vue';
import userFocus from './user-focus.vue';
import userInvite from './user-invite.vue';
import avatar_default from '@/assets/images/avatar_default.png';
import { userIndex } from '@/api/api';
import level1 from '@/assets/images/1.jpg';
import level2 from '@/assets/images/2.jpg';
import level3 from '@/assets/images/3.jpg';

export default {
  data () {
    return {
      isNormalUser: false, // 切换是否为普通用户
      partnerType:0,
      isLogin: true,
      teamData: {
        monthTotal: 3213,
        peopleTeam: 63,
        myTocash: 152.6
      },
      userInfo: {
        nickName: '昵称',
        partnerLevelname: '',
        avatar: avatar_default
      },
      baseData: {
        collectionCount: 0,
        couponCount: 0,
        integration: 0
      }
    };
  },

  activated () {
    this.getUserInfo();
  },

  methods: {
    getUserInfo () {
      userIndex().then(res => {
        const memberInfo = res.data.result;
        this.isNormalUser = !memberInfo.partner;
        this.partnerType=memberInfo.partnerType||0;
        this.userInfo.avatar = memberInfo.headPic || avatar_default;
        this.userInfo.nickName = memberInfo.nickName || '昵称';
        this.userInfo.partner = memberInfo.partner || false;
        this.userInfo.partnerLevelId = memberInfo.partnerLevelId || -1;
        this.userInfo.partnerLevelname = memberInfo.partnerLevelname || '';
        if (this.userInfo.partnerLevelId == 1) {
          this.userInfo.partnerIcon = level1;
        } else if (this.userInfo.partnerLevelId == 2) {
          this.userInfo.partnerIcon = level2;
        } else if (this.userInfo.partnerLevelId == 3) {
          this.userInfo.partnerIcon = level3;
        }
        this.teamData.monthTotal = 0;
        this.teamData.peopleTeam = memberInfo.teamPersonCount || 0;
        this.teamData.myTocash = memberInfo.commission || 0;
        this.baseData.collectionCount = memberInfo.collectionCount || 0;
        this.baseData.couponCount = memberInfo.couponCount || 0;
        this.baseData.integration = memberInfo.integration || 0;
      });
    }
  },

  components: {
    [userHeader.name]: userHeader,
    [orderGroup.name]: orderGroup,
    // [couponGroup.name]: couponGroup,
    [userModule.name]: userModule,
    userMyTeam,
    userFocus,
    userInvite
  }
};
</script>


<style scoped lang="scss">
.tabbar-user {
  > div {
    margin-bottom: 10px;
  }

  &__quit {
    border: 0;
    border-radius: 0;
  }
}
</style>
